/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MCAL_SCR_H
#define MCAL_SCR_H

#ifdef __cplusplus
extern "C" {
#endif

#include "Mcal_Types.h"
#include "Mcal_ScrBits.h"

/* Version and Check Begin */
/* Version Info Begin */
#define MCAL_SCR_H_VENDOR_ID    0x8C
#define MCAL_SCR_H_AR_RELEASE_MAJOR_VERSION    4
#define MCAL_SCR_H_AR_RELEASE_MINOR_VERSION    3
#define MCAL_SCR_H_AR_RELEASE_REVISION_VERSION 1
#define MCAL_SCR_H_SW_MAJOR_VERSION    1
#define MCAL_SCR_H_SW_MINOR_VERSION    0
#define MCAL_SCR_H_SW_PATCH_VERSION    0
/* Version Info End */

/* Version Check Begin */
#if !defined(DISABLE_MCAL_ASR_VER_CHECK)
#if ((MCAL_SCR_H_AR_RELEASE_MAJOR_VERSION != STD_TYPES_H_AR_RELEASE_MAJOR_VERSION)\
    || (MCAL_SCR_H_AR_RELEASE_MINOR_VERSION != STD_TYPES_H_AR_RELEASE_MINOR_VERSION)\
    || (MCAL_SCR_H_AR_RELEASE_REVISION_VERSION != STD_TYPES_H_AR_RELEASE_REVISION_VERSION))
#error "Opps, Mcal_Scr.h and Std_Types.h AutoSAR version not match!"
#endif
#endif  /* !DISABLE_MCAL_ASR_VER_CHECK */
#if !defined(DISABLE_MCAL_SW_VER_CHECK)
#if ((MCAL_SCR_H_SW_MAJOR_VERSION != STD_TYPES_H_SW_MAJOR_VERSION)\
    || (MCAL_SCR_H_SW_MINOR_VERSION != STD_TYPES_H_SW_MINOR_VERSION)\
    || (MCAL_SCR_H_SW_PATCH_VERSION != STD_TYPES_H_SW_PATCH_VERSION))
#error "Opps, Mcal_Scr.h and Std_Types.h Software version not match!"
#endif
#endif  /* !DISABLE_MCAL_SW_VER_CHECK */
/* Version Check End */
/* Version and Check End */

#define SCR_TYPE_MAX 0x5U

#define SCR_BITFIELD_POS_MSK    0x1FU

typedef struct {
    uint8         domain;
    uint16        type;       /* signal type */
    uint16        startBit;
    uint16        width;
} Mcal_ScrSignalType;

typedef struct {
    uint32 base;
    uint32 regOffset[SCR_TYPE_MAX];  /* register offset for different types. */
    uint32 regShift;               /* register address shift */
} Mcal_ScrDevType;
/** *****************************************************************************************************
 * \brief This function to get scr bit value of this signal.
 *
 * \verbatim
 * Syntax             : Mcal_ScrGetBit
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : signal - The system control register signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The bit value of this signal.
 *
 * Description        : This function to get scr bit value of this signal.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
uint32 Mcal_ScrGetBit(const Mcal_ScrSignalType *scrSignal);
/** *****************************************************************************************************
 * \brief This function to set scr bit value of this signal.
 *
 * \verbatim
 * Syntax             : Mcal_ScrGetBit
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : signal - The system control register signal.
 *                      value - The value will be set to this scr.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The bit value of this signal.
 *
 * Description        : This function to set scr bit value of this signal.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
Std_ReturnType Mcal_ScrSetBit(const Mcal_ScrSignalType *scrSignal, uint32 value);
/** *****************************************************************************************************
 * \brief This function to lock scr of this signal.
 *
 * \verbatim
 * Syntax             : Mcal_Ip_ScrSetBit
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : signal - The system control register signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : TRUE: This scr is locked.
 *                      FALSE: This scr doesn't need to be locked.
 *
 * Description        : This function to lock scr of this signal.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
Std_ReturnType Mcal_ScrLock(const Mcal_ScrSignalType *scrSignal);
/** *****************************************************************************************************
 * \brief This function to get if locked of this scr.
 *
 * \verbatim
 * Syntax             : Mcal_Ip_ScrReadReg
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : signal - the system control register signal.
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : TRUE: This scr is locked.
 *                      FALSE: This scr is unlocked.
 *
 * Description        : This function to get if locked of this scr.
 * \endverbatim
 * Traceability       :
 *******************************************************************************************************/
boolean Mcal_ScrIsLocked(const Mcal_ScrSignalType *scrSignal);

#ifdef __cplusplus
}
#endif

#endif  /* SCR_H */
/* End of file */
